<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head th:include="include :: header"></head>
<body>
<div class="ibox float-e-margins">
    <div class="ibox-content">
        <form class="form-horizontal m-t" id="linkUpdateForm">
            <input type="hidden" name="linkId" th:value="${link.linkId}">
            <div class="form-group">
                <label class="col-sm-3 control-label">名称：</label>
                <div class="col-sm-8">
                    <input id="linkTitle" name="title" type="text"
                           class="form-control"
                           th:value="${link.title}"
                           required="" aria-required="true">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">描述：</label>
                <div class="col-sm-8">
                    <input id="linkDescription" type="text" class="form-control"
                           name="description" required=""
                           th:value="${link.description}"
                           aria-required="true">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">链接地址：</label>
                <div class="col-sm-8">
                    <input id="linkUrl" class="form-control" name="url" required="" value="http://"
                           th:value="${link.url}">
                </div>
            </div>
            <!--            <div class="form-group">-->
            <!--                <label class="col-sm-3 control-label">链接地址：</label>-->
            <!--                <div class="col-sm-8">-->
            <!--                    <div class="input-group m-b"><span class="input-group-addon">http://</span>-->
            <!--                        <input type="text" name="url" class="form-control">-->
            <!--                    </div>-->
            <!--                </div>-->
            <!--            </div>-->
            <div class="form-group">
                <label class="col-sm-3 control-label">图标地址：</label>
                <div class="col-sm-8">
                    <input id="linkHeaderUrl" class="form-control" name="headerImg" required=""
                           th:value="${link.headerImg}">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">邮箱：</label>
                <div class="col-sm-8">
                    <input id="linkEmail" class="form-control" name="email" required="" th:value="${link.email}">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">显示：</label>
                <div class="col-sm-8">
                    <div class="onoffswitch">
                        <input type="checkbox" class="onoffswitch-checkbox"
                               th:checked="${link.display == 1 ? true : false}" id="display">
                        <label class="onoffswitch-label" for="display">
                            <span class="onoffswitch-inner"></span>
                            <span class="onoffswitch-switch"></span>
                        </label>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">权重：</label>
                <div class="col-sm-8">
                    <input id="linkWeight" class="form-control" name="weight" th:value="${link.weight}">
                </div>
            </div>
        </form>
        <div class="mail-body text-center tooltip-demo">
            <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i
                    class="fa fa-check"></i>保 存
            </button>&nbsp;
            <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i
                    class="fa fa-reply-all"></i>关 闭
            </button>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>

<script type="text/javascript">
    var prefix = ctx + "link/link";

    $("#linkAddForm").formValidate({
        rules: {
            title: {
                required: true,
                rangelength: [2, 15],
            },
            description: {
                required: true,
                rangelength: [2, 80]
            },
            url: {
                required: true,
                url: true
            },
            headerImg: {
                required: true,
            },
            email: {
                required: true,
                email: true
            },
            weight: {
                required: true,
                number: true
            },
        },
        messages: {
            "title": {
                required: "请输入标题",
                rangelength: "请输入长度为 {0} 至 {1} 之间的标题",
            },
            "description": {
                required: "请输入标题",
                rangelength: "请输入长度为 {0} 至 {1} 之间的标题"
            },
            "url": {
                required: "请输入友链地址",
                rangelength: "请输入长度为 {0} 至 {1} 之间的标题"
            },
            "email": {
                required: "请输入负责人邮箱",
                email: "请输入正确的邮箱格式"
            },
            "headerImg": {
                required: "请输入网站头像",
            },
            "weight": {
                required: "请输入权重",
                rangelength: "请输入正确格式的权重"
            },
        },
    });

    function submitHandler() {
        if ($.validate.form()) {
            var display = $("input[id='display']").is(':checked') == true ? 1 : 0;
            var data = $('#linkUpdateForm').serializeArray();
            data.push({"name": "display", "value": display})
            $.operate.saveTabPut(prefix + "/edit", data);
        }
    }
</script>
</body>
</html>